const express = require('express');
const cors = require('cors');
const path = require('path');
const multer = require('multer');

const app = express();

// 启用 CORS
app.use(cors());

// 设置静态文件目录
app.use(express.static(path.join(__dirname, 'static')));

const upload = multer({ dest: 'static/' });

app.post('/upload', upload.single('file'), (req, res) => {
  if (!req.file) {
    return res.status(400).send('No file uploaded.');
  }
  res.send('File uploaded successfully');
});

// 创建一个简单的路由
app.get('/', (req, res) => {
  res.send('Hello, World!');
});

// 启动服务
const PORT = process.env.PORT || 9005;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
